<?php

function get_review_list($con, $paradise_id = FALSE)
{
	$query = "SELECT * FROM review";
	
	if ($paradise_id !== FALSE) {
		$query .= " WHERE paradise_id = '$paradise_id'";
	}
	
	$query .= " ORDER BY id DESC";
	
	return select($con, $query);
}

function get_review($con, $id)
{
	$query = "SELECT * FROM review WHERE id = '$id' LIMIT 1";
	$records = select($con, $query);
	if(count($records) == 1) {
		return $records[0];
	}
	else {
		return NULL;
	}
}

function insert_review($con, $review)
{
	$content		= $review["content"];
	$date			= $review["date"];
	$rating			= $review["rating"];
	$paradise_id	= $review["paradise_id"];
	$user_id		= $review["user_id"];
	
	$query = "INSERT INTO review(content, date, rating, paradise_id, user_id)" .
		" VALUES ('$content', '$date', '$rating', '$paradise_id', '$user_id')";
	
	return insert($con, $query);
}

function update_review($con, $user)
{
	$id				= $review["id"];
	$content		= $review["content"];
	$date			= $review["date"];
	$rating			= $review["rating"];
	$paradise_id	= $review["paradise_id"];
	$user_id		= $review["user_id"];
	
	$query = "UPDATE review SET content = '$content', date = '$date', " .
		"rating = '$rating', paradise_id = '$paradise_id', user_id = '$user_id' " .
		"WHERE id = '$id'";
	
	return update($con, $query);
}
